Page({
  data: {
    // 页面数据
    isShow:true,
    start:"取消",
    keydata:wx.getStorageSync('keydata'),
    key:''
  },
  onShow(){
    this.setData({
      keydata:wx.getStorageSync('keydata')
    }) 
  },
  deleted(){
    wx.removeStorageSync('keydata')
    this.setData({
      keydata:wx.getStorageSync('keydata')
    }) 
  },
  clear(){
    if(this.data.start=="取消"){
      this.setData({
        key:''
      })
      wx.navigateBack({
        delta: 100, // 返回的页面数，如果 delta 大于现有页面数，则返回到首页
      });
      return;
    }
    let data = this.data.keydata.concat();
    if(data=="")data=[]
    if(this.data.key.trim()==""){
      this.setData({
        key:''
      })
      return;
    }
    data.push(this.data.key)
    wx.setStorageSync('keydata', data)
    wx.navigateTo({
      url: '../listShow/listShow?keyWord='+this.data.key
    });
    this.setData({
      keydata:wx.getStorageSync('keydata'),
      key:''
    })
  },
  onInputKey(e){
    const key = e.detail.value
    this.setData({
      key:key
    })
    if(key!=""){
      this.setData({
        start:"搜索"
      })
    }else{
      this.setData({
        start:"取消"
      })
    }
  },
  oldKey(e){
    wx.navigateTo({
      url: '../listShow/listShow?keyWord='+this.data.keydata[e.currentTarget.dataset.id]
    });
  }
  });